import { Component, Input, OnInit } from '@angular/core';
import { SPage } from '@shared/components/table-page/table-page.component';
import { ApiService } from '@core/services/api';
import { _HttpClient } from '@delon/theme';

@Component({
  selector: 'app-house-detail',
  templateUrl: './house-detail.component.html',
  styleUrls: ['./house-detail.component.less']
})
export class HouseDetailComponent implements OnInit {
  @Input()
  set _param(value) {
    this.param = value;
    this.config1.defaultParam = {houseId: value.id};
    this.config2.defaultParam = {houseId: value.id};
    this.config3.defaultParam = {houseId: value.id};
    this.config4.defaultParam = {houseId: value.id};
    this.cardStatistics(value.id);
  }
  param: any;
  // 详细信息
  itemArray: Array<{title, index, items?}>= [
    {title: '楼栋编号', index: 'houseCode'},
    {title: '楼栋名称', index: 'houseName'},
    {title: '详细地址', index: 'houseAddress'},
    {title: '门牌号', index: 'houseNumber'},
    {title: '楼栋类型', index: 'houseType', items: {
        1: '出租屋',
        2: '厂房',
        3: '公寓',
        4: '写字楼',
        5: '商业住宅',
        6: '其他',
      }},
    {title: '总层数', index: 'houseFloors'},
    {title: '房间总数', index: 'houseRooms'},
    {title: '所属街道', index: 'areaName'},
    {title: '所属派出所', index: 'policeName'},
    {title: '所在村', index: 'valligeName'},
    {title: '经度', index: 'houseLongitude'},
    {title: '纬度', index: 'houseLatitude'},

  ]
  // 主机管理
  config1: SPage = {
    columns: [
      {
        index: 'deviceCode',
        title: '主机编号',
      },
      {
        index: 'dHName',
        title: '安装位置',
      },
      {
        index: 'deviceTypeCode',
        title: '主机类型',
        filter: {
          placeholder: '请选择主机类型',
          type: 'select',
          items:[
            {label:'拍照版',value: '1'},
            {label:'视频版',value: '2'},
            {label:'录像版',value: '3'},
          ]
        }
      },
      {
        index: 'strRecordTime',
        title: '新增时间',
      }
    ],
    ps: 5,
    showCheckBox: true,
    hideSearch: true,
    reqUrl: this.api.device.listByHouseId.url,
  }
  // 管理员设置
  config2: SPage = {
    columns: [
      {
        index: 'managerName',
        title: '姓名',
        filter: {
          placeholder: '',
          hideSearch: true,
          type: 'string',
        },
      },
      {
        index: 'type',
        title: '管理员类型',
        filter: {
          placeholder: '请选择管理员类型',
          type: 'select',
          hideSearch: true,
          items: [
            { label: '业主', value: '1' },
            { label: '综管员', value: '2' },
            { label: '房屋管理员', value: '3' },
            { label: '运维人员', value: '4' },
            { label: '清洁人员', value: '5' },
          ],
        },
      },
      {
        index: 'infoMobile',
        title: '手机号码',
        filter: {
          placeholder: '请输入手机号',
          hideSearch: true,
          type: 'string',
        },
      },
      {
        index: 'addDate',
        title: '授权时间',
      },
      {
        index: 'endDate',
        title: '授权到期时间',
      }
    ],
    ps: 5,
    showCheckBox: true,
    hideSearch: true,
    reqUrl: this.api.peopleInfo.managerPage.url,

  }
  // 房间管理
  config3: SPage = {
    columns: [
      {
        index: 'roomCode',
        title: '房间编号',
        filter: {
          placeholder: '请输入房间编号',
          type: 'string'
        }
      },
      {
        index: 'roomFloor',
        title: '楼层',
        filter: {
          placeholder: '请输入楼层',
          hideSearch: true,
          type: 'string'
        }
      },
      {
        index: 'roomNumber',
        title: '房号',
        filter: {
          placeholder: '请输入房号',
          hideSearch: true,
          type: 'string'
        }
      },
      {
        index: 'roomType',
        title: '房间类型',
        filter: {
          placeholder: '请选择房间类型',
          hideSearch: true,
          type: 'select',
          items:[
            {label:'出租屋',value: '1'},
            {label:'旅店',value: '2'},
            {label:'办公室',value: '3'},
            {label:'店面',value: '4'},
          ]
        }
      },
      {
        index: 'status',
        title: '数据状态',
        filter: {
          placeholder: '请选择数据状态',
          hideSearch: true,
          type: 'select',
          items:[
            {label: '启用', value: true},
            {label: '停用', value: false},
            {label:'有效认证',value: '3'}
          ]
        }
      }
    ],
    ps: 5,
    hideSearch: true,
    showCheckBox: true,
    reqUrl: this.api.room.page.url,
  }
  // 人员管理
  config4: SPage = {
    columns: [
      {
        index: 'infoName',
        title: '姓名',
        filter: {
          hideSearch: true,
          placeholder: '请输入姓名',
          type: 'string'
        }
      },
      {
        index: 'infoSex',
        title: '性别',
        filter: {
          placeholder: '请选择性别',
          type: 'select',
          items: [
            {label: '男', value: '1'},
            {label: '女', value: '2'}
          ]
        }
      },
      {
        index: 'roomNumber',
        title: '房号',
        filter: {
          placeholder: '请输入房号',
          type: 'string'
        }
      },
      {
        index: 'infoMobile',
        title: '手机号码',
        filter: {
          placeholder: '请输入手机',
          type: 'string'
        }
      },
      {
        index: 'infoIdcardNumber',
        title: '证件号码',
        filter: {
          placeholder: '请输入证件号码',
          type: 'string'
        }
      },
      {
        index: 'infoNativeAddress',
        title: '户籍所在地',
      }
    ],
    ps: 5,
    showCheckBox: true,
    hideSearch: true,
    reqUrl: this.api.peopleInfo.page.url,
  }
  // 统计信息
  statistics = {
    peopelNum: 0,
    card: 0,
    app: 0
  }
  imgArray = ['./assets/images/1.jpg', './assets/images/2.jpg', './assets/images/3.jpg', './assets/images/4.jpg']
  constructor(
    private api: ApiService,
    private http: _HttpClient
  ) { }

  ngOnInit() {
  }
  cardStatistics(houseId): void {
    console.log(houseId)
    this.http.request<any>(this.api.peopleInfo.statistics.method, this.api.peopleInfo.statistics.url + `/${houseId}` ).subscribe(res => {
      if (res.status === '200' && res.data) {
        this.statistics.card = res.data.rsdCardTotal + res.data.cpuCardTotal + res.data.idCardTotal;
        this.statistics.app = res.data.appTotal;
        this.statistics.peopelNum = res.data.peopleTotal;
      }
    })
  }
}
